package org.bright.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component //定义为组件，交由spring管理
@Aspect //设置当前类为切面类
public class MyAdvice {
    private static final Logger logger = Logger.getLogger(MyAdvice.class);
//    @Pointcut("target(org.bright.service.Impl.BookServiceImpl)")
    @Pointcut("execution(* org.bright.service.Impl.*.*(..))")
    private void bm(){}
//    @Pointcut("execution(* org.bright..)")
//    private void bcm(){}
//    前置通知
    @Before(value = "bm()")
    public void method(){
        logger.debug("方法调用开始时间： "+System.currentTimeMillis());
    }

    @Before(value = "bm()")
    public void methodBefore( JoinPoint jp){
        logger.debug("当前调用的类是：" + jp.getTarget() + "--" + "调用的方法是："+jp.getSignature().getName()+"---");
        logger.debug("传递参数：");
        List<Object> list = Arrays.asList(jp.getArgs());
        list.forEach(System.out::println);
    }

    @After(value = "bm()")
    public void methodAfter(){
        logger.debug("方法调用结束时间： "+System.currentTimeMillis());
    }
    //    后置通知
}
